package cn.stylefeng.guns.modular.business.frequency.banner.config.activityMq;

import cn.stylefeng.guns.core.context.login.LoginContextHolder;
import cn.stylefeng.guns.modular.business.frequency.banner.config.Application;
import cn.stylefeng.guns.modular.business.frequency.orderbonus.entity.OrderBonus;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.Destination;
import java.util.Map;

/**
 * @Description:
 * @Author jzy
 * @Date 2021/1/11 0011
 **/
@Slf4j
@Component
public class Producer {

    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;

    private Destination destination = null;

    public void send(String msg) {
        log.info("activemq发送消息：{}", msg);
        destination = new ActiveMQQueue(Application.ACTIVEMQ_PREFIX + "sms.queue");
        this.jmsMessagingTemplate.convertAndSend(destination, msg);
    }

    /**
     * 奖金异步处理
     *
     * @param
     */
    public void sendBonus(Integer type, Long orderId, Long userId, Long tenantId) {
        OrderBonus orderBonus = new OrderBonus();
        orderBonus.setType(type);
        orderBonus.setOrderId(orderId);
        orderBonus.setUserId(userId);
        if (tenantId == null) {
            tenantId = LoginContextHolder.me().getSysLoginUser().getTenantId();
        }
        orderBonus.setTenantId(tenantId);
        log.info("=============activemq奖金处理发送");
        destination = new ActiveMQQueue(Application.ACTIVEMQ_PREFIX + "bonus.queue");
        String msg = JSONObject.toJSONString(orderBonus);
        this.jmsMessagingTemplate.convertAndSend(destination, msg);
    }

   /* public void sendPrePay(OrderPrepayQrcodeVO opqv) {
        log.info("=============activemq预下单发送成功");
        destination = new ActiveMQQueue(Application.ACTIVEMQ_PREFIX + "prepay.queue");
        String msg = JSONObject.toJSONString(opqv);
        this.jmsMessagingTemplate.convertAndSend(destination, msg);
    }

    public void sendWxMpTemplate(WxMpTemplate wxMpTemplate) {
        log.info("=============activemq模板消息发送");
        destination = new ActiveMQQueue(Application.ACTIVEMQ_PREFIX + "wx-template.queue");
        String msg = JSONObject.toJSONString(wxMpTemplate);
        this.jmsMessagingTemplate.convertAndSend(destination, msg);
    }

    public void sendCaptcha(Map<String, String> params) {
        log.info("=============activemq验证码消息发送成功");
        destination = new ActiveMQQueue(Application.ACTIVEMQ_PREFIX + "captcha.queue");
        String msg = JSONObject.toJSONString(params);
        this.jmsMessagingTemplate.convertAndSend(destination, msg);
    }*/
}
